package org.snusmumr.android.media.data.adapter;

import java.util.List;

import android.util.Log;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;

class CheckListenerById implements OnCheckedChangeListener {
	private static final String TAG = CheckListenerById.class.getSimpleName();
	private Long id;
	private List<Long> selected;

	public CheckListenerById(Long id, List<Long> selected) {
		super();
		this.id = id;
		this.selected = selected;
	}

	@Override
	public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
		Log.d(TAG, "checked changed id[" + id + "] isChecked: " + isChecked);
		if(id != null) {
			if(isChecked) {
				if(! selected.contains(id))
					selected.add(id);
			} else {
				selected.remove((Object)id);
			}
			onChecked(isChecked, id, selected.size());
		} else {
			Log.d(TAG, "Cannot add/remove ID to/from selected list since id is null");
		}
		
	}
	
	public void onChecked(boolean isChecked, Long id, int selectionCount) {}
}